home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CScrollList 1.0 / Demo Classes / CStringEditList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  4.9 KB  |  188 lines  |  [TEXT/KAHL]

  1. /*************************************************************************************
  2.  
  3.  CStringEditList.c
  4.     
  5.         A ScrollList that allows array element strings to be edited.
  6.     
  7.     SUPERCLASS = CScrollList
  8.     
  9.         © 1992 Dave Harkness
  10.  
  11. *************************************************************************************/
  12.  
  13.  
  14. #include "CStringEditList.h"
  15. #include "CStringArray.h"
  16.  
  17.  
  18. #define kCheckWidth            9    // room for the check mark
  19.  
  20.  
  21. extern CBureaucrat        *gGopher;
  22.  
  23.  
  24. /*************************************************************************************
  25.  IStringEditList
  26. *************************************************************************************/
  27.  
  28. void
  29. CStringEditList::IStringEditList( CView *anEnclosure, CBureaucrat *aSupervisor,
  30.                                   short aWidth, short aHeight,
  31.                                   short aHEncl, short aVEncl,
  32.                                   SizingOption aHSizing, SizingOption aVSizing,
  33.                                   short fOptions)
  34.  
  35. {
  36.     CScrollList::IScrollList( anEnclosure, aSupervisor, aWidth, aHeight,
  37.                               aHEncl, aVEncl, aHSizing, aVSizing, fOptions);
  38.     
  39.     
  40.     itsEditString = new CEditString;
  41.     itsEditString->IEditString( this, this, 0, 0, 0, 0,
  42.                                 sizFIXEDSTICKY, sizFIXEDSTICKY, -1);
  43.     itsEditString->Hide();
  44.  
  45. }  /* CStringEditList::IStringEditList */
  46.  
  47.  
  48. /*************************************************************************************
  49.  DoInsertCell  {OVERRIDE}
  50.  
  51.     Create a new string in our array.
  52. *************************************************************************************/
  53.  
  54. void
  55. CStringEditList::DoInsertCell( short beforeCell)
  56.  
  57. {
  58.     Str255        str;
  59.     
  60.     str[0] = 0;
  61.     
  62.     itsArray->InsertAtIndex( str, beforeCell);
  63.  
  64. }  /* CStringEditList::DoInsertCell */
  65.  
  66.  
  67. /*************************************************************************************
  68.  BeginEditing  {OVERRIDE}
  69.  
  70.     Create the CEditString pane.  If the editString hasn't been sized yet, it sets
  71.     its size to the correct values.
  72. *************************************************************************************/
  73.  
  74. void
  75. CStringEditList::BeginEditing( void)
  76.  
  77. {
  78.     Rect        tempRect;
  79.     
  80.     inherited::BeginEditing();
  81.     
  82.     SetRect( &tempRect, 0, 0, width - (2 * indent.h) + 2
  83.              + (kCheckWidth * ((listOptions & kSLCheckable) != 0)) - itsEditString->width,
  84.              cellHeight - 1 - itsEditString->height);
  85.     itsEditString->ChangeSize( &tempRect, kNoRedraw);
  86.     itsEditString->Place( indent.h - 1, cellHeight * (selectedCell - 1) + 1, kDontRedraw);
  87.     itsEditString->Show();
  88.     itsEditString->BecomeGopher( TRUE);
  89.     itsEditString->SelectAll( TRUE);
  90.  
  91. }  /* CStringEditList::BeginEditing */
  92.  
  93.  
  94. /*************************************************************************************
  95.  SetupCellData  {OVERRIDE}
  96.  
  97.     Place the string from the StringArray into the edit pane.
  98. *************************************************************************************/
  99.  
  100. void
  101. CStringEditList::SetupCellData( void)
  102.  
  103. {
  104.     Str255        str;
  105.     
  106.     ((CStringArray *)itsArray)->GetItem( str, selectedCell);
  107.     itsEditString->SetTextString( (StringPtr)str);
  108.  
  109. }  /* CStringEditList::SetupCellData */
  110.  
  111.  
  112. /*************************************************************************************
  113.  RetrieveCellData  {OVERRIDE}
  114.  
  115.     Take the new string from the edit pane and store it into the StringArray.
  116. *************************************************************************************/
  117.  
  118. void
  119. CStringEditList::RetrieveCellData( void)
  120.  
  121. {
  122.     Str255        str;
  123.     
  124.     itsEditString->GetTextString( (StringPtr)str);
  125.     ((CStringArray *)itsArray)->SetItem( str, selectedCell);
  126.  
  127. }  /* CStringEditList::RetrieveCellData */
  128.  
  129.  
  130. /*************************************************************************************
  131.  DoneEditing  {OVERRIDE}
  132.  
  133.     Remove the CEditString pane.
  134. *************************************************************************************/
  135.  
  136. void
  137. CStringEditList::DoneEditing( void)
  138.  
  139. {
  140.     itsEditString->Hide();
  141.     inherited::DoneEditing();                        // Now retrieve data
  142.  
  143. }  /* CStringEditList::DoneEditing */
  144.  
  145.  
  146. /*************************************************************************************
  147.  DrawCell  {OVERRIDE}
  148.  
  149.     Draw the string into the specified cell rect.
  150. *************************************************************************************/
  151.  
  152. void
  153. CStringEditList::DrawCell( short theCell, Rect *cellRect)
  154.  
  155. {
  156.     Str255    cellText;
  157.     
  158.     inherited::DrawCell( theCell, cellRect);
  159.     
  160.     ((CStringArray *)itsArray)->GetItem( cellText, theCell);
  161.     
  162.     if (cellText[0] > 0)
  163.     {
  164.         MoveTo( cellRect->left + indent.h, cellRect->top + indent.v);
  165.         DrawString( cellText);
  166.     }
  167.  
  168. }  /* CStringEditList::DrawCell */
  169.  
  170.  
  171. /*************************************************************************************
  172.  ProviderChanged  {OVERRIDE}
  173.  
  174.     If our editString is done, call DoneEditing.
  175. *************************************************************************************/
  176.  
  177. void
  178. CStringEditList::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
  179.  
  180. {
  181.     if ( reason == editStringDoneEditing && aProvider == itsEditString &&
  182.                 gGopher != itsEditString && fEditing )
  183.         DoneEditing();
  184.     else
  185.         inherited::ProviderChanged( aProvider, reason, info);
  186.  
  187. }  /* CStringEditList::ProviderChanged */
  188.